home *** CD-ROM | disk | FTP | other *** search
- Path: amaryllisp1.appsig.com!user
- From: larry_kearney@appsig.com (Larry Kearney)
- Newsgroups: comp.lang.c
- Subject: Re: Another What does this do...
- Date: Mon, 18 Mar 1996 10:50:31 -0700
- Organization: Who ever said I was organized?
- Message-ID: <larry_kearney-1803961050310001@amaryllisp1.appsig.com>
- References: <4ijkrh$8t@apollo.isisnet.com>
- NNTP-Posting-Host: amaryllisp1.appsig.com
-
- > Asside from never having programmed in C before, I figured I was doing
- > quite well until I came across the following statement:
- >
- > pb = (char *)&dop;
- >
- > where pb and dop are defined as:
- > char *pb;
- > and
- > dop is structure DOP like this:
- >
- > typedef struct doc_prop
- > {
- > int xaPage;
- > ...
- > char flandscape;
- > } DOP;
-
- What they are doing is simply casting a pointer to the memory allocated to
- dop for the structure doc_prop (represented by taking the address of dop)
- into a pointer to a char. This is then assigned to pb which is a variable
- defined as a pointer to a char.
-
- If you tried to do something like
-
- pb = &dop
-
- the compiler would complain because your are attempting to assign an
- incorrect type to pb. Casting the pointer as a char eliminates this
- complaint. I assume that they are attempting to access individual
- char-sized pieces of the structure through pb (for copying perhaps).
-
- --
- Larry Kearney | "You want fries with that?"
- Applied Signal Technology |
- larry_kearney@appsig.com |
-